<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<title>列表</title>
<script>
   $(function(){
	   //显示全部用户信息
	   $.post(
		  "/getUser",
		  function(res){
			  $.each(res,function(i,ele){
				  var ID=ele.id;
				  var userName=ele.userName;
                  var realName=ele.realName;     
                  var useTypeValue=idChangeName(ele.useType);
                  var constantName=ele.constantName;
                  var isScheduling=ele.isScheduling;
                  var deptName=ele.deptName;
                  var registName=ele.registName;
                  var value="<tr class='text-c'><td width='25'><input type='checkbox' class='check'></td>"+
                 "<td>"+ID+"</td>"+
                 "<td>"+userName+"</td>"+
                 "<td class='text-l'>"+realName+"</td>"+
                 "<td>"+useTypeValue+"</td>"+
                 "<td>"+constantName+"</td>"+
                 "<td class='td-status'><span class='label label-success radius'>"+isScheduling+"</span></td>"+
                 "<td>"+deptName+"</td>"+
                 "<td>"+registName+"</td>"+
                 "<td class='f-14 td-manage'>"+
			     "<a style='text-decoration:none' onClick='member_stop(this,'10001')' href='javascript:;' title='停用'><i class='Hui-iconfont'>&#xe631;</i></a>"+
			     "<a style='text-decoration:none' class='ml-5 updatePwd' href='javascript:;' title='修改密码'><i class='Hui-iconfont'>&#xe63f;</i></a>"+
					"<a style='text-decoration:none' class='ml-5 update' href='javascript:;' title='编辑'><i class='Hui-iconfont'>&#xe6df;</i></a>"+
					"<a style='text-decoration:none' class='ml-5 delete' href='javascript:;' title='删除'><i class='Hui-iconfont'>&#xe6e2;</i></a>"+
				"</td></tr>";            
                 $(".table").append(value);
                 $("th:eq(1)").hide();
                 $("tr").each(function(){
                	 $(this).children("td:eq(1)").hide();
                 })
			  });
			  $(".label-success").each(function(){
				  if($(this).text()=='否'){
					  $(this).css("backgroundColor","#DD514C");
				  }
				  })
				  getCount();
			  })
	   
	  //删除用户 
	   $(".table").on("click",".delete",function(){
		   var id=$(this).parents("tr").children("td:eq(1)").text();
		   var tr=$(this).parents("tr");
		   if(confirm('确认要删除吗？') ){
				$.ajax({
					url: '/deleteByID',
					data:{"id":id},
					type: 'POST',
					success: function(){
					    	$(tr).remove();
					    	getCount();
					}	
				});		
			}else{
				return false;
			}
		})
	
	
		//修改用户
		var count=0;
		$("table").on("click",".update",function(){	
			count++;
			if(count%2==1){
			$(this).parent().siblings("td").slice(2,9).css("border","1px solid black");
			$(this).parent().siblings("td").slice(2,9).prop("contenteditable","true");
			
			
			}
			else{
				$(this).parent().siblings("td").slice(2,9).css("border","1px solid #ddd");
				$(this).parent().siblings("td").slice(2,9).prop("contenteditable","false");
				
				
				var id=$(this).parents("tr").children("td:eq(1)").text();
			    var userName=$(this).parents("tr").children("td:eq(2)").text();
                var realName=$(this).parents("tr").children("td:eq(3)").text();
                var useTypeValue=$(this).parents("tr").children("td:eq(4)").text();
                var useType=nameChangeId(useTypeValue);
                var constantName=$(this).parents("tr").children("td:eq(5)").text();
                var docTitleId=null;
                var isScheduling=$(this).parents("tr").children("td:eq(6)").text();
                var deptName=$(this).parents("tr").children("td:eq(7)").text();
                var deptId=null;
                var registName=$(this).parents("tr").children("td:eq(8)").text();
                var registLeId=null;
                $.post(
                		"/getIDByConstantName",
                		{"constantName":constantName},
                		function(res){
                			docTitleId=res;
                			$.post(
                				"/getIDByDeptName",
                				{"deptName":deptName},
                				function(res1){
                					deptId=res1;
                					$.post(
                						"/getIDByRegistName",
                						{"registName":registName},
                						function(res2){
                							registLeId=res2;
                							$.ajax({
                								url:"/updateUserById",
                								data:{"id":id,"userName":userName,"realName":realName,"useType":useType,"docTitleId":docTitleId,"isScheduling":isScheduling,"deptId":deptId,"registLeId":registLeId},
                								type:"post",
                								success:function(){
                									alert("修改成功!");
                								}
                							});
                						}
                					
                					);
                				}
                			);
                		}
                		
                		);
			}
   })
   //查找用户
   $("#searchUser").on("click",function(){
	   var name=$("#name").val();
	   $("tr").each(function(){
		   if($(this).children("td:eq(2)").text()==name||$(this).children("td:eq(3)").text()==name){
			   $(this).siblings().hide();
			   $("tr:first").show();
		   }
	   })
	   
   })
  /*密码-修改*/
$("table").on("click",".updatePwd",function(){
	   var id=$(this).parents("tr").children("td:eq(1)").text();
	   var url="/goPwdUpdate?"+id;
	   change_password('修改密码',url,id,'600','270');
})
   });
</script>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>系统信息 <span class="c-gray en">&gt;</span> 用户管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c">		
	 <span class="select-box inline">
		<select name="" class="select">
			<option value="0">全部分类</option>
			<option value="1">分类一</option>
			<option value="2">分类二</option>
		</select>
		</span> 日期范围：
		<input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'logmax\')||\'%y-%M-%d\'}' })" id="logmin" class="input-text Wdate" style="width:120px;">
		-
		<input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'logmin\')}',maxDate:'%y-%M-%d' })" id="logmax" class="input-text Wdate" style="width:120px;">
		<input type="text" id="name" placeholder="请输入用户名或真实姓名" style="width:250px" class="input-text">
		<button name="" id="searchUser" class="btn btn-success"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="dataDel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> <a class="btn btn-primary radius" data-title="添加数据" onclick="member_add('添加用户', '/goMemberAdd','','510')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加数据</a></span> <span class="r">共有数据：<strong id="count">54</strong> 条</span> </div>
	<div class="mt-20">
	<div id="DataTables_Table_0_wrapper" class="DataTables_wrapper no-footer">
		<table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox"></th>
					<th width="60">ID</th>
					<th width="100">登录名</th>
					<th width="120">真实姓名</th>
					<th width="100">用户类别</th>
					<th width="120">医生职称</th>
					<th width="100">是否参与排班</th>
					<th width="100">所在科室</th>
					<th width="100">挂号级别<th>
					<th width="1"></th>
				</tr>
			</thead>
			<tbody>
			</tbody>
		</table>
		
	</div>
	</div>
</div>

<script>

//根据用户类别名找到对应的名字
function idChangeName(id){
	var name=null;
	switch(id)
    {
      case(1): 
   	   name="医院管理员";
          break;
      case(2):
    	  name="挂号收费员";
          break;
      case(3):
    	  name="门诊医生";
   	      break;
      case(4):
    	  name="医技医生";
   	      break;
      case(5):
    	  name="药房操作员";
   	      break;
      case(6):
    	  name="财务管理员";
   	      break;
      default:
   	      break;
    }
	return name;
}
function nameChangeId(name){
	var id=null;
	switch(name)
    {
      case("医院管理员"): 
   	      id=1;
          break;
      case("挂号收费员"):
    	  id=2;
          break;
      case("门诊医生"):
    	  id=3;
   	      break;
      case("医技医生"):
    	  id=4;
   	      break;
      case("药房操作员"):
    	  id=5;
   	      break;
      case("财务管理员"):
    	  id=6;
   	      break;
      default:
   	      break;
    }
	console.log(typeof id);
	return id;
}



//批量删除
function dataDel(){
	if(confirm('确认要删除吗？') ){
		$(".check:checked").each(function(){
			var id=$(this).parents("tr").children("td:eq(1)").text();
			var tr=$(this).parents("tr");
		$.ajax({
			url: '/deleteByID',
			data:{"id":id},
			type: 'POST',
			success: function(){
			    	$(tr).remove();
			    	getCount();
			}	
		});		
	})
	}else{
		return false;
	}
}
/*用户-添加*/
function member_add(title,url,w,h){
	layer_show(title,url,w,h);
	getCount();
}
/*用户-停用*/
function member_stop(obj,id){
	layer.confirm('确认要停用吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '',
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="member_start(this,id)" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe6e1;</i></a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
				$(obj).remove();
				layer.msg('已停用!',{icon: 5,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}
/*用户-启用*/
function member_start(obj,id){
	layer.confirm('确认要启用吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '',
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="member_stop(this,id)" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
				$(obj).remove();
				layer.msg('已启用!',{icon: 6,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});
	});
}
/*密码-修改*/
function change_password(title,url,id,w,h){
	layer_show(title,url,w,h);	
}
//获取数据总的条数
function getCount(){
	$("#count").text($(".table tr").length-1);
}
</script> 
</body>
</html>